package org.delphy.indy2.controls
{
	import flash.events.FocusEvent;
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	
	
	import mx.controls.List;
	import mx.controls.listClasses.IListItemRenderer;
	import mx.events.FlexEvent;
	

	public class CarbonList extends List
	{
		
		private var outterGlow:GlowFilter;
		
		public function CarbonList()
		{
			super();
			
			styleName="carbonList";
			
			outterGlow=new GlowFilter(0x6699cc,1,8,8);
			
			addEventListener(FlexEvent.CREATION_COMPLETE,onInit);
		}
		
		private function onInit(evt:FlexEvent):void{
			addEventListener(FocusEvent.FOCUS_IN,onFocusIn);
			addEventListener(FocusEvent.FOCUS_OUT,onFocusOut);			
		}
		
		private function onFocusIn(evt:FocusEvent):void{
			filters=[outterGlow];
		}
		private function onFocusOut(evt:FocusEvent):void{
			filters=[];
		}		

		 override protected function drawSelectionIndicator(
	                                indicator:Sprite, x:Number, y:Number,
	                                width:Number, height:Number, color:uint,
	                                itemRenderer:IListItemRenderer):void
	    {
	        var g:Graphics = Sprite(indicator).graphics;
	        g.clear();

	        var gradientBoxMatrix:Matrix = new Matrix();
			gradientBoxMatrix.createGradientBox(width,height, 0, 0, 0);
			g.lineStyle(2);
			g.lineGradientStyle(GradientType.LINEAR, [0x448ccb, 0xffffff], [1, 0], [0,  255], gradientBoxMatrix);
	       	g.beginGradientFill(GradientType.LINEAR, [0x448ccb, 0xffffff], [0.3, 0.05], [0,  128], gradientBoxMatrix);
	        g.drawRoundRect(1, 1, width-1, height-1,4,4);
	        g.endFill();
	        
	        var shadowFilter:DropShadowFilter=new DropShadowFilter();
	        shadowFilter.inner=true;
	        shadowFilter.blurX=8;
	        shadowFilter.blurY=8;
	        shadowFilter.distance=1;
	        shadowFilter.angle=30;
	        shadowFilter.alpha=0.35;
	        shadowFilter.color=0x448ccb;

			var glowFilter:GlowFilter=new GlowFilter();
			glowFilter.color=0x448ccb;
			glowFilter.blurX=6;
			glowFilter.blurY=6;
			
			var indicatorFilterArray:Array=[shadowFilter,glowFilter];
			
			indicator.filters=indicatorFilterArray;

	        indicator.x = x;
	        indicator.y = y;
	    }
	    override protected function drawHighlightIndicator(
	                                indicator:Sprite, x:Number, y:Number,
	                                width:Number, height:Number, color:uint,
	                                itemRenderer:IListItemRenderer):void
	    {
	        var g:Graphics = Sprite(indicator).graphics;
	        g.clear();
	        
			g.lineStyle(1,0x448ccb,1);
			g.drawRoundRect(1,1,width-1,height-1,4,4);
			
			var glowFilter:GlowFilter=new GlowFilter();
			glowFilter.color=0x448ccb;
			glowFilter.blurX=6;
			glowFilter.blurY=6;
			
			indicator.filters=[glowFilter];
	        
	        indicator.x = x;
	        indicator.y = y;
	    }
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			
			outterGlow.color=getStyle("glowColor");

		}
		
	}
}